package com.guoyan.blockchain.component.model;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;

import java.util.Date;

/**
 * @author yeym
 */

public class CalModel implements Model {
    private long time;
    private String marketName;
    private String businessName;
    private String ecrNumber;
    private int calNum;
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date calTime;
    private String ecrMac;

    @Override
    public Model fromJson(JSONObject jsonObject) {
        CalModel calModel = new CalModel();
        try {
            calModel.setTime(System.currentTimeMillis());
            calModel.setMarketName(jsonObject.getString("marketName"));
            calModel.setBusinessName(jsonObject.getString("businessName"));
            calModel.setEcrNumber(jsonObject.getString("ecrNumber"));
            calModel.setCalNum(jsonObject.getInteger("calNum"));
            calModel.setCalTime(jsonObject.getDate("calTime"));
            calModel.setEcrMac(jsonObject.getString("ecrMac"));
        } catch (Exception ignored) {
        }
        return calModel;
    }

    @Override
    public Boolean verify() {
        return this.time != 0 && this.marketName != null && this.businessName != null && this.ecrNumber != null
                && this.calNum != 0 && this.calTime != null && this.ecrMac != null;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getMarketName() {
        return marketName;
    }

    public void setMarketName(String marketName) {
        this.marketName = marketName;
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getEcrNumber() {
        return ecrNumber;
    }

    public void setEcrNumber(String ecrNumber) {
        this.ecrNumber = ecrNumber;
    }

    public int getCalNum() {
        return calNum;
    }

    public void setCalNum(int calNum) {
        this.calNum = calNum;
    }

    public Date getCalTime() {
        return calTime;
    }

    public void setCalTime(Date calTime) {
        this.calTime = calTime;
    }

    public String getEcrMac() {
        return ecrMac;
    }

    public void setEcrMac(String ecrMac) {
        this.ecrMac = ecrMac;
    }


}
